package 数组.分界求最小和;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/8/7 17:09
 * @description:
 * @version:
 */
public class Solution {
    public static void main(String[] args) {
        int[] array = {1,2,3,4,-1,5,6,3,2,4};
        System.out.println(test(array));
    }

    public static int test(int[] array) {
        boolean flag = false;
        int res = Integer.MAX_VALUE;
        int res2 = Integer.MAX_VALUE;
        for (int i = 0; i < array.length; i++) {
            int tmp = array[i];
            if (tmp == -1) {
                flag = true;
            }
            if (!flag) {
                res = res < tmp ? res : tmp;
            } else if (flag && tmp != -1){
                res2 = res2 < tmp ? res2 : tmp;
            }
        }
        return res + res2;
    }
}
